require(["core", "jQuery", "coAjax", "queryString", "href", "Cookies"], function(jSouper, $, coAjax, QueryString, href, Cookies) {
	var queryString = new QueryString;
	var reset_code = queryString.get("code");
	App.set("$Cache.find_paw.type", queryString.get("type"));
	App.set("rebackurl", queryString.get("cb"));
	if (reset_code) {
		App.set("$Cache.find_paw.url_reset_code", reset_code);
		App.set("$Cache.find_paw.find_paw_id", reset_code);
		App.set("$Cache.find_paw_steps", "2");
	}

	function _find_pwd_by_email(type, email) {
		var url = appConfig.open["find_paw_email_" + type];
		if (!url) {
			alert("error", "账号类型错误");
			return;
		}
		coAjax.post(url, {
			email: email
		}, function() {
			alert("success", "成功提交申请密码");
			App.set("$Cache.find_paw_steps", "2");
		});
	};

	function _find_pwd_by_phone(type, mobile_phone) {
		var url = appConfig.open["find_paw_phone_" + type];
		if (!url) {
			alert("error", "账号类型错误");
			return;
		}
		coAjax.post(url, {
			mobile_phone: mobile_phone
		}, function() {
			alert("success", "成功提交申请密码");
			App.set("$Cache.find_paw_steps", "2");
		});
	};


	App.set("$Event.find_paw.by_email", function() {
		var email = App.get("$Cache.find_paw.email");
		if (!email) {
			alert("warn", "您还未输入您的点纳微站账号所绑定的邮箱/手机号");
			return;
		}
		var type = App.get("$Cache.find_paw.type");
		if (!type) {
			alert("warn", "您还未选择您的账号类型");
			return;
		}
		if (email.indexOf("@") === -1) {
			_find_pwd_by_phone(type, email)
		} else {
			_find_pwd_by_email(type, email)
		}
	});


	App.set("$Event.find_paw.update_paw", function() {
		coAjax.put(appConfig.open.reset_paw_by_find_paw_id + App.get("$Cache.find_paw.find_paw_id"), {
			paw: App.get("$Cache.find_paw.new_paw"),
			confirm_paw: App.get("$Cache.find_paw.confirm_paw")
		}, function() {
			alert("success", "密码修改成功");
			App.set("$Cache.find_paw_steps", "3");
		})
	});
	App.set("$Event.find_paw.to_1", function() {
		App.set("$Cache.find_paw_steps", "1");
	});
	App.set("$Event.find_paw.to_2", function() {
		App.set("$Cache.find_paw_steps", "2");
	});
});